#include <iostream>
#include <windows.h>
using namespace std;
#pragma warning(disable : 4996)

#include <time.h>
#include "date.h"

Date::Date(int day, int month, int year)
{
	setDay(day);
	setMonth(month);
	setYear(year);
}

Date::Date()
{
	setToday();
}

void Date::setToday()
{
	time_t t = time(0);
	tm* lt = localtime(&t);
		
	day = lt->tm_mday;
	month = lt->tm_mon+1;
	year = lt->tm_year+1900;
}

void Date::setDay(int day)
{
	this->day = day;
}

void Date::setMonth(int month)
{
	this->month = month;
}

void Date::setYear(int year)
{
	this->year = year;
}

//#WD[2] RonnyR 3.12
ostream & operator<<(ostream & os,const Date & D)
{
os << D.day << "/" << D.month << "/" << D.year;
return os;	
}

istream & operator>>(istream & in,Date & D)
{
in >>D.day >>D.month>> D.year;
return in;	
}

void Date::addDays(int days)
{
FILETIME ft; 
SYSTEMTIME st;
ULONGLONG qwResult;

GetSystemTime(&st);
st.wDay = day;
st.wMonth = month;
st.wYear = year;

SystemTimeToFileTime(&st,&ft);

qwResult = (((ULONGLONG) ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
qwResult += _DAY*days;

ft.dwLowDateTime  = (DWORD) (qwResult & 0xFFFFFFFF );
ft.dwHighDateTime = (DWORD) (qwResult >> 32 );

FileTimeToSystemTime(&ft,&st);

day = st.wDay;
month = st.wMonth;
year = st.wYear;
	
}

Date operator+  (const Date& date,int num)
{
	return (num + date);
}

Date operator+  (int num,const Date& date)
{
Date tempDate;
tempDate.addDays(num);
return tempDate;
}


Date Date::operator -(int add)
{
	Date temp = *this;
	temp.addDays(-add);
	return temp;
}

const Date & Date::operator++()
{
*this = *this + 1;
return *this;	
}
Date Date::operator++(int)
{
Date temp = *this;
*this = *this + 1;	
return temp;	
}

const Date & Date::operator--()
{
*this = *this - 1;	
return *this;	
}
Date Date::operator--(int)
{
Date temp = *this;
*this = *this - 1;		
return temp;	
}
int & Date::operator[](int ind)
{
if	(ind==0)
	return day;
else if (ind==1)
	return month;
else 
	return year;

}